/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package database;

import java.sql.*;

/**
 *
 * @author Rick
 */
class mySQLUsedDAO implements UsedDAO {

    PreparedStatement ps = null;
    ResultSet rs = null;
    Connection conn = null;
    VisualizationDAO visualDAO;


    public mySQLUsedDAO() {
        conn = SQLConfigeration.getConnection();

        DAOfactory mysqlFactory =
                DAOfactory.getDAOfactory(DAOfactory.MYSQL);

        visualDAO = mysqlFactory.getVisualizationDAO();
    }

    /**
     * Used to insert values into the Used table
     *
     * @param autoID
     * @param timeStamp
     * @param visualName
     * @return boolean insertSuccess
     */
    public boolean addUsage(int autoID, String timeStamp, String visualName) {
        boolean insertSuccess = false;
        boolean visualizationExists = false;
        
        visualizationExists = visualDAO.insertVisualization(visualName);

        String insertUsed = "insert into Used(autoid,visualname, timeStamp) values (?,?,?)";
        try{
            conn.setAutoCommit(false);
            ps = conn.prepareStatement(insertUsed);
            ps.setInt(1, autoID);
            ps.setString(2, visualName);
            ps.setString(3, timeStamp);
            System.out.println("Attempting insert Used");
            ps.executeUpdate();
            conn.commit();
            System.out.println("Used Insert Successfull");
            insertSuccess = true;
        }catch(SQLException ex){
            insertSuccess = false;
            System.out.println("Used insert Error: " + ex);
        }finally{
            try {
                ps.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
        
        return insertSuccess;
    }

    /**
     * Currently not implemented
     * @return boolean delete success
     */
    public boolean deleteUsed() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * Currently not implemented
     * @return Used object
     */
    public UsedStore findUsed() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * Currently not implemented
     * @return boolean updateSuccess
     */
    public boolean updateUsed() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
